package com.approval.approvalapp.util.base;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.approval.approvalapp.R;
import com.approval.approvalapp.util.ToastUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

//输入内容的actvity
public class ContantActivity extends BaseActivity {

    @Bind(R.id.back_iv)
    ImageView backIv;
    @Bind(R.id.titleTv1)
    TextView titleTv1;
    @Bind(R.id.btn)
    Button btn;
    @Bind(R.id.et)
    EditText et;
    private String title;
    private String contant;
    public static final String returnkey = "returnkey";

    @Override
    public int getLayoutId() {
        return R.layout.activity_contant;
    }

    public static void goInto(Activity activity, int requestCode,String title, String contant){
        Intent intent = new Intent(activity,ContantActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("contant",contant);
        activity.startActivityForResult(intent,requestCode);
    }

    @Override
    public void initView() {
        title = getIntent().getStringExtra("title");
        contant = getIntent().getStringExtra("contant");

        titleTv1.setText(title);
        if (TextUtils.isEmpty(contant)){
            et.setHint("请输入" + title);
        }else {
            et.setText(contant);
            et.setSelection(et.getText().length());
        }

    }

    @Override
    public void initData() {

    }



    @OnClick({R.id.back_iv, R.id.btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.btn:
                if (et.getText().toString().length() > 0){
                    Intent intent = new Intent();
                    intent.putExtra(returnkey,et.getText().toString());
                    setResult(1001,intent);
                    finish();
                }else {
                    ToastUtil.showToast(this,"请输入内容");
                }

                break;
        }
    }


}
